package com.it.service.impl;

import com.it.common.Result;
import com.it.dao.TagsMapper;
import com.it.domain.Tags;
import com.it.service.TagsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TagsServImpl implements TagsService {

    @Autowired
    private TagsMapper tagsMapper;

    @Override
    public Object AddTags(Tags tags) {
        System.out.println(tags.getName());
        tags.setIsDelete((byte) 1);
        Tags tags1 =  tagsMapper.SelectTag(tags.getName());
        if(tags1 != null){
            return Result.fail("406","标签存在");
        }
        else{
            if(tagsMapper.AddTags(tags)>0){
                return Result.success("200","添加成功");
            }
            else{
                return Result.fail("406","添加失败");
            }
        }
    }

    @Override
    public Tags SelectTag(String name) {
        return null;
    }

    @Override
    public boolean UpdateTags(Tags tags) {
        return false;
    }

    @Override
    public Tags SelectById(Integer id) {
        return null;
    }

    @Override
    public List<Tags> SelectAll() {
        return tagsMapper.SelectAll();
    }

    @Override
    public Integer SelectTotal() {
        return tagsMapper.SelectTotal();
    }

    @Override
    public List<Tags> SelectPage(Integer pageNum, Integer pageSize, String name) {
        return tagsMapper.SelectPage(pageNum,pageSize,name);
    }

    @Override
    public List<Integer> SelectTags(String[] names) {
        return tagsMapper.SelectTags(names);
    }

    @Override
    public Object DeleteTag(Integer id) {
        if(tagsMapper.DeleteTag(id)>0){
            return Result.success("200","删除成功");
        }
        else {
            return Result.fail("403","删除失败");
        }
    }

    @Override
    public List<Tags> GetTags() {
        return tagsMapper.GetTags();
    }
}
